import {ref, computed, reactive} from 'vue'
import {defineStore} from 'pinia'


//当前用户信息
/*
* {"accountId":17089280388,"displayName":"","gameName":"我不是分奴","internalName":"","nameChangeFlag":false,"percentCompleteForNextLevel":58,"privacy":"PUBLIC","profileIconId":5178,"puuid":"cb82dd7f-2b89-5b55-ab80-3e48ceab804e","rerollPoints":{"currentPoints":500,"maxRolls":2,"numberOfRolls":2,"pointsCostToRoll":250,"pointsToReroll":0},"summonerId":17089280388,"summonerLevel":370,"tagLine":"53071","unnamed":false,"xpSinceLastLevel":2023,"xpUntilNextLevel":3456}
* */
export const devApiList = defineStore('devApiListStore', () => {
    const apis = ref([]);

        const addApi=(data)=>{
            if(data.key ===undefined){
                return ;
            }
            let hasValFlag = false;
            for (let apisKey in apis.value) {
                const item = apis.value[apisKey];
                if(item.key===data.key){
                    apis.value[apisKey]={...data}
                    hasValFlag=true;
                }
            }
            if(!hasValFlag){
                apis.value=[data,... apis.value]
            }
        }

        const deleteApi=(key)=>{
            if(key===undefined){
                return ;
            }
            apis.value = apis.value.filter(item=>{
              return   item.key!==key;
            });
        }
        return {
            apis,addApi,deleteApi
        }
    },
    {
        persist: true,
    })
